package cn.wp.common.core.web.interceptor;


import cn.wp.common.core.web.WpWebContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ServletContext上下文初始化
 * Created by chenyb on 2019-09-24
 */
public class WebContextInterceptor extends WpAbstractInterceptor {

    public WebContextInterceptor(String[] pathPatterns, String[] ignores) {
        super(pathPatterns, ignores);
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
        WpWebContext.init(new WpWebContext.Context(request,response,handler));
        return true;
    }

    @Override
    public void finalHandle(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex){
        WpWebContext.remove();
    }
}